home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
cstdio.arc
/
SRC.ARC
/
GETENV.A
< prev
next >
Wrap
Text File
|
1985-08-15
|
1KB
|
73 lines
; getenv.a - get environment string.
; (C) Copyright 1985 Cray Research Inc. - All Rights Reserved.
; G. R. Mansfield. 85/08/15.
; Ver 1.0-5815.
dseg
public _pfb
l_ebf equ 80 ; environment string buffer
ebf rb l_ebf
cseg
public getenv_
; char *getenv(name)
; char *name;
getenv_:
mov bx,sp ; requested string
mov si,[bx+2] ; toupper requested string to local string
mov cx,l_ebf
mov dx,cx
mov bx,offset ebf
mov di,bx
gev1: lodsb ; check character
or al,al
jz gev3 ; if end of string
cmp al,'a'
jl gev2 ; if not lower case
cmp al,'z'
jg gev2
sub al,'a'-'A'
gev2: stosb
loop gev1
xor ax,ax ; return NULL if string too long
ret
gev3: mov al,'=' ; add '=' for environ search
stosb
sub dx,cx ; set string length
inc dx
push ds
mov ax,_pfb ; set start of environ strings
mov ds,ax
mov ds,[02Ch]
xor si,si
mov ah,0 ; upper part of NULL for return
gev4: mov al,[si] ; check next string
or al,al
jz gev8 ; null string = end of strings
mov cx,dx ; compare strings
mov di,bx
repz cmpsb
jz gev6 ; if match found
mov cx,-1 ; skip to end of environ string
gev5: lodsb
or al,al
loopnz gev5
jmp gev4 ; next string
gev6: mov cx,l_ebf-1 ; copy string
mov di,bx
gev7: lodsb
stosb
or al,al
loopnz gev7
mov ax,offset ebf ; return pointer to string
gev8: pop ds
ret